
from tools.operate import read_dc_csv
from datetime import datetime as datetime_
import os
from tools.methods import data_df_interval


def gen_data_info(data_path):
    name = os.path.basename(data_path)
    data_df_dc: dict = read_dc_csv(data_path)
    symbol_ls = list(data_df_dc.keys())
    data_df = data_df_dc[symbol_ls[0]]
    data_len = data_df.__len__()
    if data_len == 0:
        interval_val = None
        data_modified_time = None
        start_time = None
        end_time = None
    else:
        # 从第一个symbol中获取文件相应的Interval
        interval_val = data_df_interval(data_df)

        # 获取文件的修改时间戳
        modified_timestamp = os.path.getmtime(data_path)

        # 将时间戳转换为日期格式
        data_modified_time = datetime_.fromtimestamp(modified_timestamp)
        # 数据起止时间
        start_time: datetime_ = data_df.index[0]
        end_time: datetime_ = data_df.index[-1]

    mk_data_info_dc = {"name": name,
                       "interval": interval_val,
                       "data_modified_time": data_modified_time,
                       "start_time": start_time,
                       "end_time": end_time,
                       "number": data_len,
                       "symbol": symbol_ls}
    return mk_data_info_dc



